/**
 *  StaDiUM - State Diagram Unified Modeler
 *  Copyright (C) 2007  Stefan Bucur, Mihai Balan, Claudiu Tanase
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.

 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 *  File Information
 *
 *  Last Modified On: $Date: 2007-06-14 07:08:23 +0000 (Thu, 14 Jun 2007) $
 *  Last Modified By: $Author: stefan.bucur $
 */

package ro.pub.cs.stadium.document;

import java.util.Hashtable;
import java.util.Map;

public abstract class AbstractState implements IState {
	
	private final Map<String, ITransition> inTransitions =
		new Hashtable<String, ITransition>();
	
	private final Map<String, ITransition> outTransitions =
		new Hashtable<String, ITransition>();
	
	private String name = "";
	
	private final Map<String, String> attributes =
		new Hashtable<String, String>();
	
	/**
	 * The center of the state
	 */
	private Point position = new Point(0.0f, 0.0f);

	
	public Map<String, ITransition> getInTransitions() {
		return inTransitions;
	}

	public Map<String, ITransition> getOutTransitions() {
		return outTransitions;
	}

	public Point getPosition() {
		return position.clone();
	}

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.document.IState#setPosition(ro.pub.cs.stadium.document.Point)
	 */
	public void setPosition(Point position) {
		if (position == null)
			throw new NullPointerException("position cannot be null");
		
		this.position = position.clone();
	}


	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	
	public void setAttribute(String name, String value) {
		attributes.put(name, value);
		
	}
	
	public String getAttribute(String name) {
		return attributes.get(name);
	}
	
	

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.document.IDocumentItem#getAttributes()
	 */
	public Map<String, String> getAttributes() {
		return attributes;
	}

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.document.IState#getContentSize()
	 */
	public Size getContentSize() {
		String cs = getAttribute("contentsize");
		
		if (cs != null)
			return Size.parseSize(getAttribute("contentsize"));
		else
			return null;
	}

	/* (non-Javadoc)
	 * @see ro.pub.cs.stadium.document.IState#setContentSize(ro.pub.cs.stadium.document.Size)
	 */
	public void setContentSize(Size size) {
		if (size == null)
			throw new NullPointerException("size is null");
		
		setAttribute("contentsize", size.toString());
	}

	
}
